﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
using ChatBuddy.Classes.Chat.Helpers;
using Styx.WoWInternals;

namespace ChatBuddy.Classes.Helpers.Guild_Helper
{
    class GuildLister
    {
        public int TotalGuildMembers;
        private List<GuildMember> _guildMembers; 

        private int TotalGuildies()
        {
            return Lua.GetReturnVal<int>("local numTotal, numOnline = GetNumGuildMembers(); return numTotal", 0);
        }

        public List<GuildMember> GetGuildies()
        {
            try
            {
                _guildMembers = new List<GuildMember>();
                _guildMembers.Clear();

                var numberOfGuildies = TotalGuildies();

                for (var i = 1; i <= numberOfGuildies; ++i)
                {
                    var member = Lua.GetReturnValues("return GetGuildRosterInfo(" + i + ");");
                    var guildMember = new GuildMember {User = member[0], Id = Convert.ToInt32(member[2])};
                    _guildMembers.Add(guildMember);
                }

                return _guildMembers;
            }
            catch (Exception er)
            {
                MessageBox.Show(er.ToString());
                return null;
            }
        }
    }
}
